package com.tanhua.dubbo.api;

import com.tanhua.model.mongo.Option;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

@DubboService
public class OptionApiImpl implements OptionApi{


    @Autowired
    private MongoTemplate mongoTemplate;


    @Override
    public Integer scoreNumber(List<ObjectId> ids) {
        Criteria criteria = Criteria.where("_id").in(ids);
        List<Option> options = mongoTemplate.find(Query.query(criteria), Option.class);
        // 定一个初开始的分值
        Integer score = 0;
        for (Option option : options) {
           score += option.getScore();
        }
        return score;
    }
}
